package temp;

import java.util.ArrayList;
import java.util.Random;

import algorithms.BubbleSort;
import algorithms.HeapSort;
import algorithms.QuickSort;

import other.Haus;

public class SUTRunner extends AbstractSUTRunner {

	ArrayList<Haus[]> currentParameters;
	HeapSort<Haus> heapSort = new HeapSort<Haus>();
	QuickSort<Haus> quickSort = new QuickSort<Haus>();
	BubbleSort<Haus> bubbleSort = new BubbleSort<Haus>();

	@Override
	public void setUp() {
		//TODO: setup your test data here!
		currentParameters = new ArrayList<Haus[]>();
	}

	@Override
	public void warmUp() {
		//TODO: warm up your methods in an appropriate way here!
	}

	@Override
	public void run() {
		//TODO: invoke your methods here for collecting execution profiling data!
		tesshorttHeap();
	}

	private void testQuick(){
		int step = 100000;
		int curArrayLength = 500000;
		while(curArrayLength < 500001){
			
			for(int i = 5; i < 31; i+=5){
				setUpParameters(curArrayLength,10, i);
				
				for(Haus[] h : currentParameters){
				  quickSort.sort(h, h.length, h[0].getName().length());
				}
				
			}
			curArrayLength += step;
		}			
	}
	
	private void tesshorttHeap(){
		int step = 10000;
		int curArrayLength = 10000;
		while(curArrayLength < 40001){
			
			for(int i = 5; i < 6; i++){
				setUpParameters(curArrayLength,5, i);
				
				for(Haus[] h : currentParameters){
				  heapSort.sort(h, h.length, h[0].getName().length());
				}
				
			}
			curArrayLength += step;
		}				
	}
	
	private void setUpParameters(int arraySize, int numberOfHouses, int nameLength){
		currentParameters.clear();
		int i = 0;
		while(i < numberOfHouses){
			Random r = new Random();
			Haus[] h = new Haus[arraySize];
			for(int f = 0; f < arraySize; f++){
				// build a house with given name length		
				StringBuilder name = new StringBuilder("");
				for (int e = 0; e < nameLength; e++) {
					// get random char numbers representing range from A-Z
					int decChar = r.nextInt(26) + 65;
					name.append(String.valueOf((char) decChar));
				}
				h[f] = new Haus(name.toString());			
			}
			currentParameters.add(h);
			i++;
		}
	}
}
